import Cookies from "js-cookie";
// cookie保存的天数
// import { cookieExpires } from "../../private.config";

// export const TOKEN_KEY = "190_vip_user_token";
export const TOKEN_KEY = 'web_authorization';
export const RE_TOKEN_KEY = "190_vip_user_re_token";

export default {
  set(token) {
    Cookies.set(TOKEN_KEY, token, {
      path: '/',
      expires: new Date(token.expiration) // 设置默认过期时间2小时
    });
  },
  get() {
    let token = Cookies.get(TOKEN_KEY);
    if (token) {
      token = JSON.parse(token);
      return token;
    }
    return "";
  },
  remove() {
    // const hostname = window.location.hostname.replace('user.','');
    document.cookie = TOKEN_KEY + '=0;path=/;expires=' + new Date(0).toUTCString();
    // Cookies.remove(TOKEN_KEY);
  },
  setRT(token) {
    Cookies.set(TOKEN_KEY, JSON.stringify(token), {
      expires: new Date(token.expiration)
    });
  },
  getRT(key = "") {
    let token = Cookies.get(TOKEN_KEY);
    if (token) {
      token = JSON.parse(token);
      return token[key];
    }
    return "";
  },
  setRTByKey(key = "", value = "") {
    let token = Cookies.get(TOKEN_KEY);
    if (token) {
      token = JSON.parse(token);
      token[key] = value;
      Cookies.set(TOKEN_KEY, JSON.stringify(token), {
        expires: new Date(token.expiration),
      });
    }
  },
  removeRT() {
    Cookies.remove(TOKEN_KEY);
  },
};
